# -*- coding: utf-8 -*-
from time import sleep

import allure
from common.page import Page
from regression_service_rdc.funtion.fun_main_rdc import MainRdc
from regression_service_rdc.page_elements.el_application_management_rdc import application_management_rdc

# 应用列表页面
class ApplicationListRdc(MainRdc):
    @allure.step('step:产品型_新建应用')
    def create_product_application(self):
        Page.click(application_management_rdc, '应用管理页面', '新建应用')
        return ProductCreateApplication1()

    @allure.step('step:项目型_新建应用')
    def create_project_application(self):
        Page.click(application_management_rdc, '应用管理页面', '新建应用')
        return ProjectCreateApplication1()

    @allure.step('step:在应用名称搜索框输入名称搜索')
    def sendkeys_lookup_application_name(self, application_name):
        Page.send_key(application_management_rdc, '应用管理页面', '应用名称搜索框', application_name)
        sleep(1)
        return self

    @allure.step('step:返回查找到的第一个应用名称')
    def __lookup_application_name_text(self):
        name_text = Page.element_text(application_management_rdc, '应用管理页面', '应用名称')
        print(name_text)
        return name_text

    @allure.step('step:断言新建应用名称与输入名称一致')
    def assert_name_equal(self, expect_name):
        """
        :param expect_name: 预期的应用名称
        :param lookup_name: 实际查找到的应用名称
        :return:
        """
        name_text = self.__lookup_application_name_text()
        Page.assert_equal(expect_name,name_text)
        return self

    @allure.step('step:断言查找到的应用状态为【开发中】')
    def assert_application_state(self,expect_state):
        # 等待应用状态变为[失败]或者[开发中]
        state_text = Page.wait_not_text(application_management_rdc, '应用管理页面', '应用状态')
        Page.assert_equal(state_text,expect_state)
        return self

    @allure.step('step:删除查找到的第一个应用')
    def delete_lookup_application_name(self):
        Page.click(application_management_rdc,'应用管理页面','删除第一个应用')
        sleep(0.5)
        Page.click(application_management_rdc,'应用管理页面','确认删除')
        sleep(2)
        return self

    @allure.step('step:断言删除成功')
    def assert_delete_lookup_application_name(self):
        state_text = Page.element_text(application_management_rdc,'应用管理页面', '应用状态')
        print(state_text)
        return state_text

# 产品型_创建应用页面1
class ProductCreateApplication1:
    @allure.step('step:点击云ERP产品应用')
    def click_pc_new_application(self):
        Page.click(application_management_rdc, '产品型_新建应用页面', '云ERP产品应用')
        return self

    @allure.step('step:点击下一步')
    def click_determine(self):
        Page.click(application_management_rdc, '产品型_新建应用页面', '下一步')
        return ProductCreateApplication2()

# 产品型_云ERP产品_创建应用页面2
class ProductCreateApplication2:

    @allure.step('step:输入应用名称')
    def sendkeys_application_name(self, application_name):
        """
        :param application_name:
        :return:
        """
        Page.send_key(application_management_rdc, '产品型_云ERP产品应用', '应用名称', application_name)
        return self

    @allure.step('step:点击确定')
    def click_next(self):
        Page.click(application_management_rdc, '产品型_云ERP产品应用', '确定')
        return ApplicationListRdc()

# 项目型_创建应用页面1
class ProjectCreateApplication1:

    @allure.step('step:点击云ERP定制应用')
    def click_erp_customized_application(self):
        Page.click(application_management_rdc, '项目型_新建应用页面', '云ERP定制应用')
        return self

    @allure.step('step:点击下一步')
    def click_next(self):
        Page.click(application_management_rdc, '项目型_新建应用页面', '下一步')
        return ProjectCreateApplication2()

# 项目型_云ERP定制应用_创建应用页面1
class ProjectCreateApplication2:
    @allure.step('step:输入应用名称')
    def sendkeys_application_name(self,application_name):
        Page.send_key(application_management_rdc, '项目型_云ERP定制应用', '应用名称',application_name)
        return self

    @allure.step('step:选择扩展产品')
    def select_extended_products(self):
        Page.click(application_management_rdc, '项目型_云ERP定制应用', '点击请选择扩展产品')
        sleep(1)
        Page.click(application_management_rdc, '项目型_云ERP定制应用', '选择扩张产品_数据中台web')
        return self

    @allure.step('step:点击确定')
    def click_determine(self):
        Page.click(application_management_rdc, '项目型_云ERP定制应用', '确定')
        # sleep(20)
        return ApplicationListRdc()



